(require 'redo)
(require 'rect-mark)                                        ; 
(autoload 'rm-set-mark "rect-mark"
  "Set mark for rectangle." t) 
(autoload 'rm-exchange-point-and-mark "rect-mark"
  "Exchange point and mark for rectangle." t) 
(autoload 'rm-kill-region "rect-mark"
  "Kill a rectangular region and save it in the kill ring." t) 
(autoload 'rm-kill-ring-save "rect-mark"
  "Copy a rectangular region to the kill ring." t) 
(autoload 'rm-mouse-drag-region "rect-mark"
  "Drag out a rectangular region with the mouse." t) 
;; Use this section in your "~/.emacs" to modify picture mode so that 
;; it automatically uses the rect-mark equivalents of many commands. 
;; One vision of a better picture mode. 

(autoload 'rm-example-picture-mode-bindings "rect-mark"
  "Example rect-mark key and mouse bindings for picture mode.")
(require 'browse-kill-ring)
(browse-kill-ring-default-keybindings)

(defun recentf-open-files-compl ()
  (interactive)
  (let* ((all-files recentf-list)
         (tocpl (mapcar (function 
                         (lambda (x) (cons (file-name-nondirectory x) x))) all-files))
         (prompt (append '("File name: ") tocpl))
         (fname (completing-read (car prompt) (cdr prompt) nil nil)))
    (find-file (cdr (assoc-string fname tocpl))))) 

;; (defun ska-point-to-register()
;;   "Store cursorposition _fast_ in a register. 
;; Use ska-jump-to-register to jump back to the stored 
;; position."
;;   (interactive)
;;   (setq zmacs-region-stays t)
;;   (point-to-register 8))
;; (defun ska-jump-to-register()
;;   "Switches between current cursorposition and position
;; that was stored with ska-point-to-register."
;;   (interactive)
;;   (setq zmacs-region-stays t)
;;   (let ((tmp (point-marker)))
;;     (jump-to-register 8)
;;     (set-register 8 tmp)))
(require 'ido)
(defun ido-my-keys ()
  "Set up the keymap for `ido'."
  ;; common keys
  (define-key ido-completion-map "\C-e" 'ido-edit-input)
  (define-key ido-completion-map "\t" 'ido-complete) ;; complete partial
  (define-key ido-completion-map "\C-j" 'ido-select-text)
  (define-key ido-completion-map "\C-m" 'ido-exit-minibuffer)
  (define-key ido-completion-map "?" 'ido-completion-help) ;; list completions
  (define-key ido-completion-map [(control ? )] 'ido-restrict-to-matches)
  (define-key ido-completion-map [(control ?@)] 'ido-restrict-to-matches)
  ;; cycle through matches
  (define-key ido-completion-map "\C-r" 'ido-prev-match)
  (define-key ido-completion-map "\C-s" 'ido-next-match)
  (define-key ido-completion-map [right] 'ido-next-match)
  (define-key ido-completion-map [left] 'ido-prev-match)
  ;; toggles
  (define-key ido-completion-map "\C-t" 'ido-toggle-regexp) ;; same as in isearch
  (define-key ido-completion-map "\C-p" 'ido-toggle-prefix)
  (define-key ido-completion-map "\C-c" 'ido-toggle-case)
  (define-key ido-completion-map "\C-a" 'ido-toggle-ignore)

  ;; keys used in file and dir environment
  (when (memq ido-cur-item '(file dir))
    (define-key ido-completion-map "\C-b" 'ido-enter-switch-buffer)
    (define-key ido-completion-map "\C-d" 'ido-enter-dired)
    (define-key ido-completion-map "\C-f" 'ido-fallback-command)
    (define-key ido-completion-map [down] 'ido-next-match-dir)
    (define-key ido-completion-map [up]   'ido-prev-match-dir)
    (define-key ido-completion-map [backspace] 'ido-delete-backward-updir)
    (define-key ido-completion-map [deletechar] 'ido-delete-backward-updir)
    (define-key ido-completion-map "\d"        'ido-delete-backward-updir)
    (define-key ido-completion-map [(meta backspace)] 'ido-delete-backward-word-updir)
    (define-key ido-completion-map [(control backspace)] 'ido-up-directory)
    (define-key ido-completion-map [(meta ?d)] 'ido-wide-find-dir)
    (define-key ido-completion-map [(meta ?f)] 'ido-wide-find-file)
    (define-key ido-completion-map [(meta ?k)] 'ido-forget-work-directory)
    (define-key ido-completion-map [(meta ?m)] 'ido-make-directory)
    (define-key ido-completion-map [(meta down)] 'ido-next-work-directory)
    (define-key ido-completion-map [(meta up)] 'ido-prev-work-directory)
    (define-key ido-completion-map [(meta left)] 'ido-prev-work-file)
    (define-key ido-completion-map [(meta right)] 'ido-next-work-file)
    ;; search in the directories
    ;; use C-_ to undo this
    (define-key ido-completion-map [(meta ?s)] 'ido-merge-work-directories)
    (define-key ido-completion-map [(control ?\_)] 'ido-undo-merge-work-directory)
    )
  (when (eq ido-cur-item 'file)
    (define-key ido-completion-map "\C-k" 'ido-delete-file-at-head)
    (define-key ido-completion-map "\C-l" 'ido-toggle-literal)
    (define-key ido-completion-map "\C-o" 'ido-copy-current-word)
    (define-key ido-completion-map "\C-v" 'ido-toggle-vc)
    (define-key ido-completion-map "\C-w" 'ido-copy-current-file-name)
    )
  (when (eq ido-cur-item 'buffer)
    (define-key ido-completion-map "\C-b" 'ido-fallback-command)
    (define-key ido-completion-map "\C-f" 'ido-enter-find-file)
    (define-key ido-completion-map "\C-k" 'ido-kill-buffer-at-head)
    ))
